from types import FunctionType
from datetime import datetime

a = """
def main(device):
    print("test", device)
    return {
        "topic": "测试",
        "payload": "hhh"
    }
"""

# f = compile(source=a, filename="", mode="exec")
# mainFunc = None
# for func in f.co_consts:
#     if func and func.co_name and func.co_name == "main":
#         print(func.co_name)
#         mainFunc = FunctionType(func, {"now": datetime.now})
# if mainFunc:
#     a = mainFunc("test")
#     print(a)

import nmcli

nmcli.device.show("lan0")